{{extend "base.html"}}

{{block head}}

    <script>
	
		var datagrid;
		$(function(){
			datagrid=$('#data').datagrid({
				url: '/operationpost/applicationtype',
				iconCls:'icon-tip',
				width:'auto',
				height:'auto',
				title: '',
				nowrap: true,
				autoRowHeight: false,
				striped: true,
				collapsible:true,
				idField:'id',
				pagination:true,  //分页
				//rownumbers:true, //显示行号
				pageSize:20,
				pageList:[20,30],
				//loadMsg:'正在载入数据...',
				//自适应高度
				fit:true,
				//自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动
				fitColumns: true,
				frozenColumns : [ [ {
					title : '编号',
					field : 'id',
					width : 150,
					sortable : true,
					checkbox : true
				}, {
					title : '应用主题',
					field : 'applicationtype_name',
					width : 100,
					sortable : true
				} ] ],
				columns:[[{
						field:'department_name',
						title:'部门',
						width:100
					}, {
						field:'opersgroup_name',
						title:'运营组',
						width:100
					}, {
						field:'ogproject_name',
						title:'运营组项目',
						width:100
					}, {
						field:'applicationtype_dep_env',
						title:'应用部署环境要求',
						width:200
					}, {
						field:'applicationtype_dep_doc',
						title:'应用部署文档',
						width:100,
						formatter : function(value, row) {
							var str='';
							str += '<a href="javascript:void(0);" onclick="showdocFun(' + row.id + ');"><span class="ext-icon-note" title="查看" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span></a>'
							str += '<a href="javascript:void(0);" onclick="editdocFun(' + row.id + ');"><span class="ext-icon-note_edit" title="编辑" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span></a>'
							return str;
						}
					}, {
						field:'comment',
						title:'备注',
						width:100
					},
				]],
				toolbar:[ {
					text : '增加',
					iconCls : 'icon-add',
					handler : function() {
						append();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						remove();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						edit();
					}
				}, '-', {
					text : '取消选中',
					iconCls : 'icon-undo',
					handler : function() {
						datagrid.datagrid('clearSelections');
						datagrid.datagrid('unselectAll');
					}
				}, '-'],

			}); 
		});
		
    function edit() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var p = parent.sy.dialog({
				title : '编辑应用主题',
				href : '/operation/applicationtypeedit?id=' + rows[0].id,
				width : 600,
				height : 300,
				buttons : [ {
					text : '编辑',
					handler : function() {
						var f = p.find('form');
						f.form('submit', {
							url : '/operation/applicationtypesave',
							success : function(d) {
								var json = $.parseJSON(d);
								if (json.success) {
									datagrid.datagrid('reload');
									p.dialog('close');
								}
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						});
					}
				} ],
				onLoad : function() {
					var f = p.find('form');
					f.form('load', {
						id : rows[0].id,
						applicationtype_name : rows[0].applicationtype_name,
						applicationtype_dep_env:rows[0].applicationtype_dep_env,
						comment : rows[0].comment,
					});
				}
			});
		} else if (rows.length > 1) {
			parent.sy.messagerAlert('提示', '同一时间只能编辑一条记录！', 'error');
		} else {
			parent.sy.messagerAlert('提示', '请选择要编辑的记录！', 'error');
		}
	}
	function append() {
		var p = parent.sy.dialog({
			title : '添加',
			href : '/operation/applicationtypeadd',
			width : 600,
			height : 300,
			buttons : [ {
				text : '添加应用主题',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '/operation/applicationtypesave',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : '/operation/applicationtypedel',
						data : {
							id : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请勾选要删除的记录！', 'error');
		}
	}
	
	var editdocFun = function(id) {
		var dialog = parent.sy.modalDialog({
			title : '编辑应用部署文档',
			url : '/ueditor/applicationtypedocedit?flag=applicationtype&id=' + id,
			width : 1024,
			height : 600,
			buttons : [ {
				text : '编辑',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, datagrid, parent.$, parent.mainMenu);
				}
			} ]
		});
	};
	
	var showdocFun = function(id) {
		var dialog = parent.sy.modalDialog({
			title : '查看应用部署文档',
			url : '/ueditor/applicationtypedocshow?flag=applicationtype&id=' + id,
			width : 1024,
			height : 600
		});
	};
	</script>
{{end}}

{{block content}}

<table id="data"></table>

{{end}}
